package cn.tedu.medicalpath.role.controller;

import cn.tedu.medicalpath.base.response.JsonResult;
import cn.tedu.medicalpath.role.pojo.dto.RoleQuery;
import cn.tedu.medicalpath.role.pojo.dto.RoleSaveParam;
import cn.tedu.medicalpath.role.pojo.entity.Role;
import cn.tedu.medicalpath.role.pojo.vo.RoleVO;
import cn.tedu.medicalpath.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("select")
    public JsonResult selectRole(RoleQuery roleQuery){
        log.debug("开始处理【查询角色信息】的请求，参数：{}",roleQuery);
        List<RoleVO> list = roleService.selectRole(roleQuery);
        return JsonResult.success(list);
    }

    @PostMapping("insert")
    public JsonResult insert(RoleSaveParam roleSaveParam){
        log.debug("开始处理【新增角色信息】的请求，参数：{}",roleSaveParam);
        roleService.insert(roleSaveParam);
        return JsonResult.success();
    }

    @PostMapping("delete")
    public JsonResult delete(@RequestParam Integer id){
        log.debug("开始处理【删除角色信息】的请求，参数：{}",id);
        roleService.delete(id);
        return JsonResult.success();
    }

    @GetMapping("selectById")
    public JsonResult selectById(@RequestParam Integer id){
        log.debug("开始处理【根据ID查询角色信息】的请求，参数：{}",id);
        RoleVO roleVO = roleService.selectRoleById(id);
        return JsonResult.success(roleVO);
    }
}